﻿define(["jQuery", "kendo", "config", "utils", "localdata", "viewModels/driverDataSources"],
        function ($, kendo, config, utils, localdata, ds) {

            var validator,
            
                // _viewModel private
                _viewModel = kendo.observable({
                    drivers : ds.driverDataSource,              /*drivers datasource*/
                    saveDriver: function () {
                        if (validator.validate()) {
                            this.dataSource.sync();
                        }
                    }
                });     //end viewmodel

            //_addDriverClick
            var _addDriverClick = function(){
                console.log('entering: viewModel.driver._addDriverClick');

                _viewModel.drivers.add({
                    Name: $("#txtfullname").val(),
                    Email: $("#txtemail").val(),
                    Telephone: $("#txtcontact").val()
                });

                //send it to the server
                _viewModel.drivers.sync();

                console.log('immediately after synch');
                utils.navigate(config.paths.driverMain);
            }

            /*RETURN*/
            return {
                addDriverClick: _addDriverClick,
                viewModel: _viewModel,
                show: function () {
                    console.log('entering: viewModel.driver.show');
                }
            }

        }); /* End define */